<template>
	<view class="searchLayout">
		<u-search placeholder="请输入搜索内容" @search="onSearch" @custom="onSearch" :clearabled="true" :showAction="true" actionText="搜索" :animation="true"
			v-model="keyword"></u-search>
			
		<view class="historyList">
			<view class="item" v-for="(item,i) in historyList" :key="i">
				<view class="text">{{item}}</view>
				<view class="close">
					<u-icon name="close" size="16" color="#999" @click="onClose(i)"></u-icon>
				</view>
			</view>
		</view>	
	</view>
</template>

<script>
	export default {
		data() {
			return {
				keyword: '',
				historyList:[]
			};
		},
		onLoad() {
			this.historyList=uni.getStorageSync("historyList") || [];
		},
		methods:{
			onSearch(){
				this.historyList.unshift(this.keyword);
				this.historyList=[...new Set(this.historyList)];
				uni.setStorageSync("historyList",this.historyList);
			},
			onClose(i){
				this.historyList.splice(i,1);
				uni.setStorageSync("historyList",this.historyList);
			}
		}
	}
</script>

<style lang="scss" scoped>
	.searchLayout{
		padding: 30rpx;
		.historyList{
			margin-top: 30rpx;
			.item{
				@include flex-box();
				font-size: 32rpx;
				padding: 30rpx 0;
				color: #333;
				border-bottom: 1px solid $border-color-light;
			}
		}
	}
</style>